import PageHeader from '@/components/PageHeader';
import { submitForm } from '@/services/form';
import { Field, Form, Input, Message, ResponsiveGrid } from '@alifd/next';
import { definePageConfig, history, useSearchParams } from 'ice';
import { useEffect, useState } from 'react';

const { Cell } = ResponsiveGrid;
const FormItem = Form.Item;
export default function DailyIndex() {
    const [searchParams, _] = useSearchParams();
    useEffect(() => {
        function getDateObj(date) {
            const year = date.getFullYear();
            const month = date.getMonth() + 1;
            const day = date.getDate();
            const hour = date.getHours();
            const minute = date.getMinutes();
            return {
                year,
                month,
                day,
                hour,
                minute,
                dateStr: `${year}_${month}_${day}`,
                dateDianStr: `${year}.${month}.${day}`
            }
        }
        var dateObj = getDateObj(new Date());
        if (dateObj.hour < 12) {
            dateObj = getDateObj(new Date(new Date().getTime() - 3600 * 24 * 1000));
        }
        const type = searchParams.get('type');
        if (type == 'reminder') {
            history?.push('/daily_remind?date=day_' + dateObj.dateDianStr, {
            });
        } else {
            history?.push('/daily?date=day_' + dateObj.dateDianStr, {
            });
        }
        // history?.push('/daily?date=day_' + dateObj.dateDianStr, {
        // });
    }, []);
    // 负责跳转
    return null;
}

export const pageConfig = definePageConfig(() => {
    return {
        auth: ['admin', 'user'],
        title: '日常跳转',
    };
});
